package Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import Entities.SaleResponseEntity;
import GUI.SaleResponsesReportGUI;

/**
 * The Class SaleResponsesReportController.
 * Controller for creating sale responses reports.
 */
public class SaleResponsesReportController {

	/** The srr gui. */
	private SaleResponsesReportGUI srrGUI;
	
	/** The srr entity. */
	private SaleResponseEntity srrEnt;
	
	/** The previous. */
	private ReportsController prev;
	
	/**
	 * Instantiates a new sale responses report controller.
	 *
	 * @param srrGUI the srr gui
	 * @param srrEnt the srr entity
	 */
	public SaleResponsesReportController(SaleResponsesReportGUI srrGUI,
			SaleResponseEntity srrEnt) {
		
		this.srrGUI = srrGUI;
		this.srrEnt = srrEnt;
		this.srrGUI.addBackListener(new BackListener());
		addDataToList();
		this.srrGUI.setVisible(true);
	}
	
	/**
	 * Adds the data to list.
	 */
	public void addDataToList()
	{
		String[] listdata=new String[5+srrEnt.getResponses().size()];
		listdata[0]="Sale id : "+srrEnt.getSid();
		listdata[1]="#Potential customers: "+srrEnt.getAmountOfCustomers();
		listdata[2]="Total phone time : "+srrEnt.getSumOfTimeOnPhone();
		listdata[3]="Sales made : "+srrEnt.getEvents();
		listdata[4]="Customers rejection comments:";
		for(int i=5;i<srrEnt.getResponses().size()+5;i++)
			listdata[i]=srrEnt.getResponses().get(i-5);	
			
		srrGUI.getList().setListData(listdata);
	}
	
	/**
	 * The listener interface for receiving back events.
	 * The class that is interested in processing a back
	 * event implements this interface, and the object created
	 * with that class is registered with a component using the
	 * component's <code>addBackListener<code> method. When
	 * the back event occurs, that object's appropriate
	 * method is invoked.
	 *
	 * @see BackEvent
	 */
	class BackListener implements ActionListener
	{

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			LoginController.mainWindow.setTitle("Reports");
			LoginController.mainWindow.setContentPane(prev.getrGUI());
		}
		
	}
	
	/**
	 * Sets the previous.
	 *
	 * @param reportsController the new previous
	 */
	public void setPrev(ReportsController reportsController) {
		prev= reportsController;
		
	}

	/**
	 * Gets the srr gui.
	 *
	 * @return the srr gui
	 */
	public SaleResponsesReportGUI getSrrGUI() {
		return srrGUI;
	}

	/**
	 * Sets the srr gui.
	 *
	 * @param srrGUI the new srr gui
	 */
	public void setSrrGUI(SaleResponsesReportGUI srrGUI) {
		this.srrGUI = srrGUI;
	}

	/**
	 * Gets the srr ent.
	 *
	 * @return the srr ent
	 */
	public SaleResponseEntity getSrrEnt() {
		return srrEnt;
	}

	/**
	 * Sets the srr ent.
	 *
	 * @param srrEnt the new srr entity
	 */
	public void setSrrEnt(SaleResponseEntity srrEnt) {
		this.srrEnt = srrEnt;
	}

	/**
	 * Gets the previous.
	 *
	 * @return the previous
	 */
	public ReportsController getPrev() {
		return prev;
	}
	
}
